package com.gton.lpl.common.pojo;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @description: 自定义统一返回json格式
 * @author: GuoTong
 * @createTime: 2021-10-05 16:07
 * @since JDK 1.8 OR 11
 **/
@Data
@Accessors(chain = true)
@SuppressWarnings("all")
public class Resp<T> {
    //状态码
    private int code;

    //提示信息
    private String msg;

    //返回的数据
    private T data;


    /**
     * Description:常用返回数据抽离
     */
    public static <T> Resp<T> LoginOk() {
        return new Resp<T>().
                setCode(CodeTools.LOGIN_SUCCESS_CODE).
                setMsg(CodeTools.LOGIN_SUCCESS_TIP);
    }

    public static <T> Resp<T> LoginFail() {
        return new Resp<T>().
                setCode(CodeTools.LOGIN_FAIL_CODE).
                setMsg(CodeTools.LOGIN_FAIL_TIP);
    }

    public static <T> Resp<T> error(String errorMsg) {
        return new Resp<T>().
                setCode(CodeTools.FAIL_CODE).
                setMsg(errorMsg);
    }

    public static <T> Resp<T> error(String errorMsg,int code) {
        return new Resp<T>().
                setCode(CodeTools.FAIL_CODE).
                setMsg(errorMsg);
    }

    public static <T> Resp<T> Ok(T data) {
        return new Resp<T>().
                setCode(CodeTools.SUCCESS_CODE).
                setMsg(CodeTools.SUCCESS).
                setData(data);
    }
}
